"use strict";

import Ajax from "../libs/ajax";
import Constant from "../libs/constants";

export default {
    set_users_show(data) {
        return Ajax.ajax({
            url: Constant.URL_SET_USERS_SHOW,
            method: 'post',
            data: {
                type: 5,
                value: data
            }
        }).then(res => res.data);
    },
    get_users_show() {
        return Ajax.ajax({
            url: Constant.URL_GET_USERS_SHOW,
            method: 'get'
        }).then(res => res.data);
    },
    /**
     * 
     * data.type png|jpg
     * data.data base64 code
     */
    set_logo(data) {
        return Ajax.ajax({
            url: Constant.URL_SET_LOGO,
            method: 'post',
            data: {
                type: 4,
                value: data
            }
        }).then(res => res && res.data);
    },
    get_logo() {
        return Ajax.ajax({
            url: Constant.URL_GET_LOGO,
            method: 'get'
        }).then(res => res && res.data);
    },
    query(user_type, custom_type) {
        let params = [];
        if (user_type != undefined) {
            params.push('user_type=' + user_type);
        }
        if (custom_type != undefined) {
            params.push('custom_type=' + custom_type);
        }
        return Ajax.ajax({
            url: Constant.URL_CUSTOM_QUERY + '?' + params.join('&'),
            method: 'get'
        }).then(res => res.data)
    },
    add(params) {
        return Ajax.ajax({
            url: Constant.URL_CUSTOM_ADD,
            method: 'post',
            data: params
        }).then(res => res.data);
    },
    update(params) {
        return Ajax.ajax({
            url: Constant.URL_CUSTOM_UPDATE,
            method: 'post',
            data: params
        }).then(res => res.data);
    },
    delete(custom_id) {
        if (!custom_id)
            return;
        return Ajax.ajax({
            url: Constant.URL_CUSTOM_DELETE,
            method: 'post',
            data: {
                custom_id: custom_id
            }
        }).then(res => res.data);
    }
}
